'''def extract_graphs(move,infile,outfile,resultfile,size,producer,consumer,demand):
  lines = open(infile).readlines()
  m = 0 
  a = re.compile("^graph.*")
  x = re.compile("^shortest paths.*")
  y = re.compile("^\*\*\*\*\*.*")
  z = re.compile("^src.*")
  line = ""      
  i = 0
  reqline = "" 
  while (i < len(lines) and m < move):
    line = lines[i]
    if re.match(a,line):
      reqline = line
      m +=1
    i += 1
  line = reqline
  line = line.replace("[", "")
  line = line.replace("]", "")
  line = line.replace("\'", "")
  line = line.replace("\n", "")
  arr = line.split(":")[1].split(",")
  #print arr
  generate_gams(arr,producer,consumer,outfile,resultfile,size, demand )


files = '0 1 2 3 4 5 6 7 8 9'
print files.split(" ")
producer = ['0','2','11','13']
consumer = ['10','5','16','12','4','1','19','18']
size = 20
demandDays = 2
#os.system("cd Data/GAMS/gamscode5/; rm -r d*")
#extract_graphs(1,"5-2-4", "gamsdir/gilma", "result.out", size,producer,consumer, ['0 -150','1 50', '2 0', '3 0' ,'4 150'])

d = 0
demands = {}
lines = open("Data/DemandData.txt").readlines() 
for line in lines:
  arr = line.split('\t')
  i = 0 
  demandTotal = 0
  demand = []
  while i < size: 
    if str(i) in consumer:
      index =  random.randrange(0,48)
      demand.append(str(i) + " "+ arr[index])
      demandTotal += int(arr[index])
      print arr[index]
    else:
      demand.append(str(i) + " 0")
    i += 1
  for j in producer:
    demand[int(j)] = j + " " +   str(-1*demandTotal/len(producer))
  demands[d] =  demand
  d += 1

for d in demands.keys():
  print "mkdir gamsdir/demand" + str(d)
  #os.system("mkdir Data/GAMS/gamsdir5")
  os.system("mkdir Data/GAMS/gamscode" + str(size) +"/demand" + str(d))
  for i in files.split(" "):
    move = random.randrange(1,3)
    extract_graphs(move,"Data/GAMS/"+ i, "Data/GAMS/gamscode"+str(size) + "/demand"+str(d)+"/gams"+i+"demand"+str(d) ,"demand"+str(d)+"-result"+i+".out", size,producer,consumer,demands[d])
    #extract_graphs(2,i, "gamsdir/demand"+str(d)+"/gams"+i+"demand"+str(d) ,"demand"+str(d)+"-result"+i+".out", size,producer,consumer,demands[d])
'''

